package com.onpositive.knowledge.model.values;

import com.onpositive.knowledge.model.value.audits.AbstractAuditResult;
import com.onpositive.knowledge.model.value.audits.GeneralAuditResult;
import com.onpositive.semantic.model.api.meta.IMeta;
import com.onpositive.semantic.model.api.property.IProperty;

public class AuditedProperty implements IProperty{
	
	protected final IHasGeneralAuditResult r;
	protected final IProperty base;

	public AuditedProperty(IHasGeneralAuditResult r, IProperty base) {
		super();
		this.r = r;
		this.base = base;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((base == null) ? 0 : base.hashCode());
		result = prime * result + ((r == null) ? 0 : r.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AuditedProperty other = (AuditedProperty) obj;
		if (base == null) {
			if (other.base != null)
				return false;
		} else if (!base.equals(other.base))
			return false;
		if (r == null) {
			if (other.r != null)
				return false;
		} else if (!r.equals(other.r))
			return false;
		return true;
	}

	@Override
	
	public IMeta getMeta() {
		return base.getMeta();
	}
	@Override
	public String getId() {
		return base.getId();
	}
	@Override
	public Object getValue(Object obj) {
		GeneralAuditResult auditResult = r.getAuditResult();
		AbstractAuditResult result = auditResult.getResult(getId());
		if (result.isSuspicios(obj)){
			return null;
		}
		Object value = base.getValue(obj);
		return value;
	}
}
